//
//  ZYMainViewController.swift
//  ZYweibo
//
//  Created by apple on 15/12/20.
//  Copyright © 2015年 zhuyipeng. All rights reserved.
//

import UIKit

class ZYMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
        
        
        let mainTabBar = ZYmainTaBar()
        setValue(mainTabBar, forKey: "tabBar")//tabBar一定不能写错
        
        
        
        let home = ZYHomeController()
        self.addchildVC(home, title: "首页", name: "tabbar_home")
        
        let message = ZYMessageController()
        self.addchildVC(message, title: "消息", name: "tabbar_message_center")
        
        let discovery = ZYDiscoveryController()
        self.addchildVC(discovery, title: "发现", name:"tabbar_discover")
        
        let profile = ZYProfileController()
        self.addchildVC(profile, title: "我", name: "tabbar_profile")

        
    }

    func addchildVC(controller : UIViewController,title : String,name : String){
        self.addChildViewController(UINavigationController(rootViewController: controller))
        controller.title = title
        controller.tabBarItem.image = UIImage(named: name)
        let newName = name + "_highlighted"
        controller.tabBarItem.selectedImage = UIImage(named:newName)?.imageWithRenderingMode(UIImageRenderingMode.AlwaysOriginal)
        controller.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName:UIColor.orangeColor()], forState: UIControlState.Selected)
        
        
        
    }

}
